package ArrayAndString;

public class RerverseWords {
    public String reverseWords(String s) {
        String[] strings = s.split(" ");
        StringBuilder sb = new StringBuilder();
        for (int i = strings.length - 1; i >= 0 ; i--) {
            if(!strings[i].equals("")){
                sb.append(strings[i] +" ");
            }
        }
        String s1 = sb.toString();
        return s1.trim();
    }

    public static void main(String[] args) {
        RerverseWords rerverseWords = new RerverseWords();
        String s = " Hello   World  ";
        String s1 = rerverseWords.reverseWords(s);
        System.out.println(s1);

    }
}
